import React, { Component } from 'react'
import { withRouter } from '_react-router-dom@5.3.4@react-router-dom/cjs/react-router-dom.min'

class Header extends Component {
    //一般组件不用withRouter包裹暴露无法收到路由参数
    goup=()=>{
        this.props.history.goForward()
        // this.props.history.go(1)
      }
      godown=()=>{
        this.props.history.goBack()
        // this.props.history.go(-1)
      }  
  render() {
    // console.log('这是Header组件（非路由组件的props）'+JSON.stringify(this.props));
    return (
        <div>
            <div>React路由学习</div>
            <button style={{marginLeft:"6px"}} onClick={this.goup}>前进</button>
            <button style={{marginLeft:"6px"}} onClick={this.godown}>后退</button>
        </div>
     
    )
  }
}

export default withRouter(Header)
// export default Header
// withRouter可以加工一般组件，让一般组件具有路由组件的所有API